# -*- coding: utf-8 -*-
import scrapy
from sina.items import SinaItem

class SinaspiderSpider(scrapy.Spider):
    name = 'sinaSpider'
    allowed_domains = ['http://news.sina.com.cn']
    start_urls = ['http://news.sina.com.cn/']

    def make_requests_from_url(self, url):
        url = 'http://news.sina.com.cn/guide/'
        """ This method is deprecated. """
        return scrapy.Request(url, dont_filter=True)

    def parse(self, response):
    	dataList = response.css('.section div.clearfix')
    	for _list in dataList:
    		guideType = _list.css('h3::text').extract_first()
    		if guideType == None:
    			guideType = _list.css('h3 a::text,h3 span::text').extract_first()
    		guide_list = _list.css('li')
    		for g in guide_list:
    			item = SinaItem()
	    		item['guideType'] = guideType
	    		item['url'] = g.css('a::attr(href)').extract_first()
	    		item['title'] = g.css('a::text').extract_first()
	    		yield(item)

